home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
3100
/
3100.xpi
/
chrome
/
content
/
js
/
clickclean.js
next >
Wrap
Text File
|
2010-01-23
|
7KB
|
257 lines
// Click&Clean, MIT, <http://www.hotcleaner.com/>. Copyright Mixesoft(c)Project 2004-2010 <http://www.mixesoft.com/>
addEventListener('unload', function() {
clickClean(1);
}, false);
function clickClean(bClose, ui) {
if (ui) {
clearUI(ui-1);
return;
}
var sanitize = true,
close = false,
showPrompt = true,
wait = 8,
useExt = false,
closeExt = false,
path = '',
arg = '',
tabs = false,
tab = false,
lso = false,
file,
proc;
readPrefs();
if(useExt || closeExt) {
file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
proc = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
}
if (bClose) {
if (findWindow("navigator:browser"))
return;
tabs = useExt = sanitize = false;
}
else
close = closeExt = false;
if (tabs)
clearUI(tab);
if (lso)
clearLSO();
if (sanitize || close)
clearBrowsingData();
else if (useExt || closeExt)
runExt();
else
return;
function clearLSO() {
var OS = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULRuntime).OS.toLowerCase();
var props = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
var dir, path;
if (OS == 'linux') {
dir = props.get('Home', Components.interfaces.nsIFile);
path = dir.path + "/.macromedia/Flash_Player/#SharedObjects";
rem();
path = dir.path + "/.macromedia/Flash_Player/macromedia.com/support/flashplayer/sys"
rem();
}
else if (OS == 'darwin') {
dir = props.get('ULibDir', Components.interfaces.nsIFile);
path = dir.path + "/Preferences/Macromedia/Flash Player/#SharedObjects";
rem();
path = dir.path + "/Preferences/Macromedia/Flash Player/macromedia.com/support/flashplayer/sys"
rem();
}
else { // win
dir = props.get('AppData', Components.interfaces.nsIFile);
path = dir.path + '\\Macromedia\\Flash Player\\#SharedObjects';
rem();
path = dir.path + "\\Macromedia\\Flash Player\\macromedia.com\\support\\flashplayer\\sys"
rem();
}
function rem() {
try {
file.initWithPath(path);
if (file.exists)
file.remove(true);
} catch (e){};
}
}
function clearUI(tab) {
var m = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
if (m) {
var recent = m.getMostRecentWindow("navigator:browser");
// enum and close all windows but keep selected
var e = m.getEnumerator('');
if (e) {
var w;
while(e.hasMoreElements()) {
w = e.getNext();
// close tabs
if (w == recent) {
var b = w.gBrowser;
if (!tab)
b.selectedTab = b.addTab('about:blank');
b.removeAllTabsBut(b.selectedTab);
}
else
w.close();
}
}
}
}
function clearBrowsingData() {
if (!sanitize && !close) {
if (useExt || closeExt)
runExt();
return;
}
if (!showPrompt)
wait = 0;
var wdlg = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(null, "chrome://browser/content/sanitize.xul", null, "chrome,centerscreen", null);
wdlg.addEventListener('load', function() {
var tid = 0;
wdlg.addEventListener('unload', function(e) {
// case cancel
if (tid)
wdlg.clearTimeout(tid);
// run external app
if (useExt || closeExt)
runExt();
}, false)
var dlg = wdlg.document.getElementsByTagName('prefwindow');
dlg = dlg[0];
if (wait < 1) {
dlg.acceptDialog();
return;
}
if(wait > 7)
return;
var btn = dlg.getButton('accept');
if (btn) {
var i = wait;
var label = btn.label;
function setLabel() {
btn.label = label+' ('+i+')';
if (i < 1)
dlg.acceptDialog();
else {
--i;
tid = wdlg.setTimeout(setLabel, 1000);
}
}
setLabel();
}
}, false);
}
function runExt() {
file.initWithPath(path);
proc.init(file);
proc.run(false, [arg], 1);
}
function readPrefs(bDef) {
var prefs = findWindow("ccOptions");
if (prefs) {
prefs = prefs.document;
sanitize = prefs.getElementById('san-enabled').checked;
close = prefs.getElementById('san-close').checked;
showPrompt = prefs.getElementById('san-ask').checked;
wait = prefs.getElementById('san-time').selectedIndex;
useExt = prefs.getElementById('ext-sanitize').checked;
closeExt = prefs.getElementById('ext-close').checked;
path = prefs.getElementById('ext-path').value;
arg = prefs.getElementById('ext-arg').value;
lso = prefs.getElementById('adv-lso').checked;
tabs = prefs.getElementById('adv-tabs').checked;
tab = prefs.getElementById('adv-tab').checked;
}
else {
prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.clickclean.");
sanitize = prefs.getBoolPref('sanitize');
close = prefs.getBoolPref('close');
showPrompt = prefs.getBoolPref('showPrompt');
wait = prefs.getIntPref('wait');
useExt = prefs.getBoolPref('useExt');
closeExt = prefs.getBoolPref('closeExt');
path = prefs.getComplexValue("path", Components.interfaces.nsISupportsString).data;
arg = prefs.getComplexValue("arg", Components.interfaces.nsISupportsString).data;
lso = prefs.getBoolPref('lso');
tabs = prefs.getBoolPref('tabs');
tab = prefs.getBoolPref('tab');
}
}
function LOG(text) {
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(text);
}
function findWindow(sType) {
return Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow(sType);
}
}